#ifndef _ABACUSIM_INSTRUCTION_H_
#define _ABACUSIM_INSTRUCTION_H_

/* An instruction is a 32-bit unsigned int */
typedef unsigned int Inst;

/** 
 * to retrieve elements of an instruction
 */

/* R type */
#define inst_op(inst)        (inst & 0xFC000000) /* 31:26 the most significant 6 bits */
#define inst_rs(inst)        (inst & 0x03E00000) /* 25:21 next 5 bits */
#define inst_rt(inst)        (inst & 0x001F0000) /* 20:16 next 5 bits */
#define inst_rd(inst)        (inst & 0x0000F800) /* 15:11 next 5 bits */
#define inst_sa(inst)        (inst & 0x000007C0) /* 10:6  next 5 bits, shift amount */
#define inst_funct6(inst)    (inst & 0x0000003F) /* 5:0 the least significant 6 bits */

/* I type */
#define inst_base(inst)      (inst & 0x03E00000) /* same as inst_rs in R type */
#define inst_dst(inst)       (inst & 0x001F0000) /* same as inst_rt in R type */
#define inst_offset(inst)    (inst & 0x0000FFFF) /* 15:0 the least significant 16 bits */

/* J type */
#define inst_target(inst)    (inst & 0x03FFFFFF) /* 25:0 the least significant 26 bits */

#endif	/*  _ABACUSIM_INSTRUCTION_H_ */
